import { getCurrentInstance, reactive, ref } from 'vue';

export default function importConfig() {
  const data = ref([]);

  const base = reactive<any>({
    size: 'medium',
    columns: [
      {
        title: '工单编码',
        dataIndex: 'company',
        checked: true,
      },
      {
        title: '订单编号',
        dataIndex: 'creator',
        checked: true,
      },
      {
        title: '客户名称',
        dataIndex: 'ma001',
        checked: true,
      },
      {
        title: '产品编号',
        dataIndex: 'ma002',
        checked: true,
      },
      {
        title: '产品名称',
        dataIndex: 'ma003',
        checked: true,
      },
      {
        title: '规格型号',
        dataIndex: 'ma011',
        checked: true,
      },
      {
        title: '单位',
        dataIndex: 'ma012',
        checked: true,
      },
      {
        title: '生产进度',
        dataIndex: 'ma013',
        checked: true,
      },
      {
        title: '需求日期',
        dataIndex: 'ma013',
        checked: true,
      },
    ],
    pagination: {
      defaultPageSize: 10,
      total: 1, //总条数
      current: 1,
      pageSize: 10,
      showTotal: true,
      showPageSize: true,
      pageSizeOptions: [10, 20, 30, 40, 50],
    },
    // 查询参数
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      workorderCode: null,
      workorderName: null,
      orderSource: null,
      sourceCode: null,
      productId: null,
      productCode: null,
      productName: null,
      productSpc: null,
      unitOfMeasure: null,
      quantity: null,
      quantityProduced: null,
      quantityChanged: null,
      quantityScheduled: null,
      clientId: null,
      clientCode: null,
      clientName: null,
      requestDate: null,
      parentId: null,
      ancestors: null,
      status: null,
    },
    // tasks:{
    //   data: [],
    //   links: [],
    // },
    tasks: {
      data: [
        {
          id: 'MO12',
          type: 'project',
          text: '色粉【蓝色】10g',
          workstation: null,
          product: '色粉【蓝色】',
          quantity: 10,
          progress: 0,
          color: null,
          process: null,
          parent: null,
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO10',
          type: 'project',
          text: '螺丝刀10000PCS',
          workstation: null,
          product: '螺丝刀',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: null,
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO11',
          type: 'project',
          text: '螺丝刀刀头10000PCS',
          workstation: null,
          product: '螺丝刀刀头',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: 'MO10',
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO9',
          type: 'project',
          text: '螺丝刀9999PCS',
          workstation: null,
          product: '螺丝刀',
          quantity: 9999,
          progress: 0,
          color: null,
          process: null,
          parent: null,
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO4',
          type: 'project',
          text: '移液盒10000PCS',
          workstation: null,
          product: '移液盒',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: null,
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO5',
          type: 'project',
          text: '透明盒体10000PCS',
          workstation: null,
          product: '透明盒体',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: 'MO4',
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO6',
          type: 'project',
          text: '吸头320000PCS',
          workstation: null,
          product: '吸头',
          quantity: 320000,
          progress: 0,
          color: null,
          process: null,
          parent: 'MO4',
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: 'MO1',
          type: 'project',
          text: '螺丝刀10000PCS',
          workstation: null,
          product: '螺丝刀',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: null,
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: '203',
          type: 'task',
          text: '螺丝刀5000PCS',
          workstation: '1#组装工作站',
          product: '螺丝刀',
          quantity: 5000,
          progress: 0,
          color: '#00AEF3',
          process: '组装',
          parent: 'MO1',
          start_date: '2023-09-05 00:00:00',
          duration: 2,
          end_date: null,
        },
        {
          id: '204',
          type: 'task',
          text: '螺丝刀5000PCS',
          workstation: '2#组装工作站',
          product: '螺丝刀',
          quantity: 5000,
          progress: 0,
          color: '#00AEF3',
          process: '组装',
          parent: 'MO1',
          start_date: '2023-09-05 00:00:00',
          duration: 1,
          end_date: null,
        },
        {
          id: 'MO2',
          type: 'project',
          text: '螺丝刀刀柄10000PCS',
          workstation: null,
          product: '螺丝刀刀柄',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: 'MO1',
          start_date: null,
          duration: 2,
          end_date: null,
        },
        {
          id: 'MO3',
          type: 'project',
          text: '螺丝刀刀头10000PCS',
          workstation: null,
          product: '螺丝刀刀头',
          quantity: 10000,
          progress: 0,
          color: null,
          process: null,
          parent: 'MO1',
          start_date: null,
          duration: 0,
          end_date: null,
        },
        {
          id: '200',
          type: 'task',
          text: '螺丝刀刀头1PCS',
          workstation: '1#五金切割工作站',
          product: '螺丝刀刀头',
          quantity: 1,
          progress: 0,
          color: '#00AEF3',
          process: '板材剪贴',
          parent: 'MO3',
          start_date: '2023-08-20 00:00:00',
          duration: 1,
          end_date: null,
        },
        {
          id: '201',
          type: 'task',
          text: '螺丝刀刀头1PCS',
          workstation: '2#冲压工作站',
          product: '螺丝刀刀头',
          quantity: 1,
          progress: 0,
          color: '#00AEF3',
          process: '冲压',
          parent: 'MO3',
          start_date: '2023-08-20 00:00:00',
          duration: 1,
          end_date: null,
        },
        {
          id: '202',
          type: 'task',
          text: '螺丝刀刀头1PCS',
          workstation: '喷涂工作站',
          product: '螺丝刀刀头',
          quantity: 1,
          progress: 0,
          color: '#00AEF3',
          process: '喷涂',
          parent: 'MO3',
          start_date: '2023-08-20 00:00:00',
          duration: 1,
          end_date: null,
        },
      ],
      links: [],
    },
    // changedTaskIds:
  });

  const { proxy } = getCurrentInstance();

  const deviceStatusList = [
    {
      name: '设备总数',
      icon: 'icon-settings',
      num: 102400,
    },
    {
      name: '运行中',
      icon: 'icon-play-circle-fill',
      color: 'green',
      num: 10,
    },
    {
      name: '待机',
      icon: 'icon-pause-circle-fill',
      color: 'orange',
      num: 102,
    },
    {
      name: '故障',
      icon: 'icon-exclamation-circle-fill',
      color: 'red',
      num: 10400,
    },
  ];
  //表格数据
  const getTableData = (flag: string) => {
    // if (flag == "search") {
    //   base.pagination.current = 1;
    //   base.pagination.pageSize = 10;
    // }
    // const reqParam = {
    //   page: base.pagination.current,
    //   pageSize: base.pagination.pageSize,
    // };
    // let req = getInitParam(queryDataFilter(collection));
    // req = Object.assign(...req, reqParam);
    // purmamPage(req).then((res) => {
    //   data.value = res.data.records;
    //   base.pagination.total = res.data.total;
    // });
  };
  //初始化
  const init = () => {
    getTableData('search');
  };
  //点击搜索按钮发生的事件
  const tapDate = () => {
    getTableData('search');
  };
  //页数改变
  const handlePageChange = (page: number) => {
    base.pagination.current = page;
    getTableData('handleChange');
  };
  //页面大小改变
  const handlePageSizeChange = (pageSize: number) => {
    base.pagination.pageSize = pageSize;
    getTableData('handleChange');
  };
  //获取甘特图数据
  const getGanttTasks = () => {
    // listGanttTaskList(base.queryParams).then(response =>{
    //   base.tasks.data = response.data.data;
    //   base.tasks.links = response.data.links;
    //   proxy?.$refs.ganttChar.reload();
    // });
  };

  return {
    base,
    data,
    deviceStatusList,
    init,
    tapDate,
    handlePageChange,
    handlePageSizeChange,
    getGanttTasks,
  };
}
